package com.ptszyxx.popose.module.main.mine.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.databinding.ItemMineRechargeBinding;
import com.ysg.http.data.entity.mine.MineDiamondEntity;
import com.ysg.utils.YCollectionUtil;

import java.util.List;

public class MineRechargeAdapter extends BaseQuickAdapter<MineDiamondEntity, BaseDataBindingHolder<ItemMineRechargeBinding>> {
    private Presenter mPresenter = new Presenter();


    public MineRechargeAdapter() {
        super(R.layout.item_mine_recharge);
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemMineRechargeBinding> holder, MineDiamondEntity item) {
        ItemMineRechargeBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
//            binding.setViewModel(viewModel);
            binding.setPresenter(mPresenter);
            binding.setPosition(holder.getBindingAdapterPosition());
            binding.executePendingBindings();

            if (item.isChecked()){
                binding.parent.setBackgroundResource(R.drawable.shape_mine_recharge_check_bg);
            }else{
                binding.parent.setBackgroundResource(R.drawable.shape_mine_recharge_uncheck_bg);
            }

            binding.parent.setOnClickListener((v)->{
                List<MineDiamondEntity> list = MineRechargeAdapter.this.getData();
                if (YCollectionUtil.isNotEmpty(list)){
                    for (MineDiamondEntity entity: list) {
                        entity.setChecked(false);
                    }
                    item.setChecked(true);
                    notifyDataSetChanged();
                }
            });


        }
    }

    public static class Presenter{
//        public void onItemClick(HomeVM viewModel, HomeResult entity){
//            viewModel.jumpPersonDetail(entity);
//        }
//        public void onHeartClick(HomeVM viewModel, HomeResult entity, int position){
//            viewModel.heart(entity, position);
//        }
//        public void onChatClick(HomeVM viewModel, HomeResult entity){
//            viewModel.jumpChat(entity);
//        }
    }







}
